/*
 * Created by JFormDesigner on Wed Dec 15 14:55:12 CST 2021
 */

package com.cn.项目.飞机预约管理系统.Maininterface;

import com.cn.项目.utils.JdbcUtils;

import java.awt.*;
import java.awt.event.*;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import javax.swing.*;

public class DeletePassenger extends JPanel {
    public DeletePassenger() {
        initComponents();
    }

    //删除监听
    private void button1ActionPerformed(ActionEvent e) {
        // TODO add your code here
        Connection conn = null;
        PreparedStatement st = null;
        ResultSet rs =null;
        String pname = textField1.getText();
        String dname = textField2.getText();

        try {
            conn = JdbcUtils.getConnection();
            String sql = "delete from passenger where pname=? and dname=? ";
            st = conn.prepareStatement(sql);
            st.setString(1, pname);
            st.setString(2, dname);
            int i = st.executeUpdate();
            if (i>0){
                new Success();
            }else {
                new Fail();
            }
        } catch (SQLException e1) {
            e1.printStackTrace();
        }finally {
            JdbcUtils.release(conn,st ,rs );
        }
    }

    private void initComponents() {
        // JFormDesigner - Component initialization - DO NOT MODIFY  //GEN-BEGIN:initComponents
        label1 = new JLabel();
        label2 = new JLabel();
        label3 = new JLabel();
        textField1 = new JTextField();
        textField2 = new JTextField();
        button1 = new JButton();

        //======== this ========
        setLayout(null);

        //---- label1 ----
        label1.setText("删除乘客");
        label1.setFont(label1.getFont().deriveFont(label1.getFont().getSize() + 16f));
        label1.setForeground(new Color(204, 0, 0));
        add(label1);
        label1.setBounds(125, 5, 195, 42);

        //---- label2 ----
        label2.setText("乘客姓名");
        label2.setFont(label2.getFont().deriveFont(label2.getFont().getSize() + 6f));
        add(label2);
        label2.setBounds(40, 85, 110, 40);

        //---- label3 ----
        label3.setText("代买人");
        label3.setFont(label3.getFont().deriveFont(label3.getFont().getSize() + 6f));
        add(label3);
        label3.setBounds(40, 150, 110, 40);
        add(textField1);
        textField1.setBounds(180, 85, 150, 35);
        add(textField2);
        textField2.setBounds(180, 155, 150, 35);

        //---- button1 ----
        button1.setText("删除");
        button1.setFont(button1.getFont().deriveFont(button1.getFont().getSize() + 6f));
        button1.setForeground(new Color(204, 0, 0));
        button1.addActionListener(e -> button1ActionPerformed(e));
        add(button1);
        button1.setBounds(125, 235, 100, 35);

        { // compute preferred size
            Dimension preferredSize = new Dimension();
            for(int i = 0; i < getComponentCount(); i++) {
                Rectangle bounds = getComponent(i).getBounds();
                preferredSize.width = Math.max(bounds.x + bounds.width, preferredSize.width);
                preferredSize.height = Math.max(bounds.y + bounds.height, preferredSize.height);
            }
            Insets insets = getInsets();
            preferredSize.width += insets.right;
            preferredSize.height += insets.bottom;
            setMinimumSize(preferredSize);
            setPreferredSize(preferredSize);
        }
        // JFormDesigner - End of component initialization  //GEN-END:initComponents
    }

    // JFormDesigner - Variables declaration - DO NOT MODIFY  //GEN-BEGIN:variables
    private JLabel label1;
    private JLabel label2;
    private JLabel label3;
    private JTextField textField1;
    private JTextField textField2;
    private JButton button1;
    // JFormDesigner - End of variables declaration  //GEN-END:variables
}
